<?php

use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
use PhpAmqpLib\Wire\AMQPTable;

require __DIR__ . '/../../vendor/autoload.php';

$config = require(__DIR__ . '/../config.php');
$connection = new AMQPStreamConnection(
    $config['host'],
    $config['port'],
    $config['user'],
    $config['password'],
    $config['vhost']
);

$channel = $connection->channel();

const DELAY_EXCHANGE = 'delay_exchange';
$channel->exchange_declare(DELAY_EXCHANGE, 'x-delayed-message', false, false, false, false, false, new AMQPTable([
    'x-delayed-type' => 'direct',
]));

foreach(range(0, 10) as $index) {
    $msg = new AMQPMessage('tttt ' . $index, [
        'x-delay' => 10*1000
    ]);

    $channel->basic_publish($msg, DELAY_EXCHANGE, 'rk_delay');
    echo "send msg: ".$index . PHP_EOL;
}

echo "done";